package io.renren.modules.member.enums;

import io.swagger.models.auth.In;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;

import java.util.Optional;

@Getter
@RequiredArgsConstructor
public enum MemberTypeEnums {

    ONE(1, "一类人员"),

    TWO(2, "二类人员"),

    THREE(3, "三类人员");

    private final Integer code;
    private final String text;

    public static String getTextFromCode(Integer code) {
        String result = "";
        for (MemberTypeEnums type : values()) {
            if (Optional.ofNullable(code).orElse(0).equals(type.code)) {
                result = type.getText();
                break;
            }
        }
        return  result;
    }

    public static Integer getCodeFromText(String text) {
        Integer result = 0;
        for (MemberTypeEnums type : values()) {
            if (StringUtils.equals(type.getText(), text)) {
                result = type.getCode();
                break;
            }
        }
        return  result;
    }
}
